<template>
    <div>
        <h2>充值</h2>
        <table class="table table-bordered">
            <tr>
                <td align="right">金额</td>
                <td><input type="text"  v-model="money" ></td>
            </tr>
            <tr>
                <td align="right">支付方式</td>
                <td><input type="radio" name="money">现金
                    <input type="radio" name="money">微信
                    <input type="radio" name="money">支付宝
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="充值" @click="ok()" />

                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import { onMounted, reactive, toRefs } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import axios from 'axios';
const router = useRouter()
const route = useRoute()
let data = reactive({
    money: ''
})
let { money } = toRefs(data)
const ok = () => {
    if (money.value == "") {
        alert("金额不能为空")
    }
    if (isNaN(Number(money.value)) == true) {
        alert("金额必须是数字")
        return
    }
    if (Number(money.value) < 0) {
        alert("金额不能为负数")
        return
    }
    axios({
        url: '/api/Member/UpdateMemberMoney',
        method: 'put',
        params: { id: route.query.id, money: money.value }
    })
    
        .then(res => {
            console.log(res)
            if(res.data.data==1){
                alert("充值成功")
                router.push('/list')
            }
            else{
                alert("重置失败")
            }
        })
        .catch(err => {
            console.log(err)
        })
}
</script>

<style scoped></style>